// 成绩管理页面
<template>
	<div class="all">
		<div id="searchdiv" style="float: right;margin-bottom: 10px;width: 350px;">
			<el-input placeholder="请输入内容" v-model="input" class="input-with-select">
				<el-button @click="searchMessage()" slot="append" icon="el-icon-search"></el-button>
			</el-input>
		</div>

		<el-table :data="pagination.records" border>
			<el-table-column fixed="left" prop="scoreId" label="成绩编号" sortable></el-table-column>
			<el-table-column prop="exam.examName" label="考试名称"></el-table-column>
			<el-table-column prop="student.userName" label="学生名称"></el-table-column>
			<el-table-column prop="totalScore" label="总分" sortable></el-table-column>
			<el-table-column prop="joinTime" label="参考时间"></el-table-column>
			<el-table-column prop="submitTime" label="交卷时间"></el-table-column>
			<el-table-column label="操作" align='center'>
				<template slot-scope="scope">
					<el-button size="mini" @click="handleEdit(scope.$index, scope.row)">重新评分</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.current"
		 :page-sizes="[6, 10]" :page-size="pagination.size" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
		 class="page">
		</el-pagination>

		<!--重新评分-->
		<el-dialog title="重新评分" :visible.sync="dialogTableVisible" width="50%" :before-close="handleClose">
			<el-table :data="gridData">
				<el-table-column property="ts.topicName" label="题目" width="150"></el-table-column>
				<el-table-column property="ts.topicAnswer" label="标准答案" width="200"></el-table-column>
				<el-table-column property="answer.answerContent" label="学生答案"></el-table-column>
				<el-table-column property="ts.topicScore" label="分值" ></el-table-column>
				<el-table-column property="answer.socre" label="原评分" ></el-table-column>

				<el-table-column label="评分" width="180" >
					<template slot-scope="scope">
						<el-input-number :min="0" :max="scope.row.ts.topicScore" size="small" type="primary" v-model="scope.row.score" @change="updScore(scope.$index, scope.row)"></el-input-number>
					</template>
				</el-table-column>

			</el-table>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogTableVisible = false">取 消</el-button>
				<el-button type="primary" @click="submit()">确 定</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				pagination: {
					//分页后的考试信息
					current: 1, //当前页
					total: null, //记录条数
					size: 6, //每页条数
				},
				dialogTableVisible: false, //增加的对话框
				form: {

				}, //保存点击以后当前试卷的信息
				course: [],
				input: "",
				select: "全部",
				gridData: [],
				examId: "",
				userId: "",
				scoreId: ""
			};
		},
		created() {
			this.getScoreInfo();
		},
		methods: {
			getScoreInfo() {
				//分页查询所有信息
				this.$axios('/api/getScore', {
					params: {
						keywords: '',
						page: this.pagination.current,
						limit: this.pagination.size
					}
				}).then(res => {
					this.pagination = res.data;
				}).catch(error => {});
			},
			//改变当前记录条数
			handleSizeChange(val) {
				this.pagination.size = val;
				this.getScoreInfo();
			},
			//改变当前页码，重新发送请求
			handleCurrentChange(val) {
				this.pagination.current = val;
				this.getScoreInfo();
			},
			submit() { //提交更改
				this.dialogTableVisible = false;
			},
			//模糊检索
			searchMessage() {
				this.$axios('/api/getScore', {
					params: {
						keywords: this.input,
						page: this.pagination.current,
						limit: this.pagination.size
					}
				}).then(res => {
					this.pagination = res.data;
				}).catch(error => {});

			},
			handleClose(done) {
				this.dialogTableVisible = false;
			},
			//获取某个同学的综合题信息
			handleEdit: function(index, row) {
				this.examId = row.exam.examId;
				this.userId = row.student.userId;
				this.scoreId = row.scoreId;
				this.dialogTableVisible = true;
				console.log(row.exam.examId + "," + row.student.userId);
				this.$axios('api/getAnswers', {
						params: {
							'examId': row.exam.examId,
							'userId': row.student.userId,
						}
					})
					.then((res) => {
						this.gridData = res.data;
					})
					.catch(function(error) {
						console.log(error)
					})

			},
			//修改分数
			updScore(index, row) {
				console.log("回答编号：" + row.answer.answerId);
				console.log("分数："+row.score);
				if (row.score != undefined) {
					this.$axios('api/updTotalScore', {
							params: {
								answerId: row.answer.answerId,
								score: row.score,
								examId: this.examId,
								userId: this.userId,
								scoreId: this.scoreId
							}
						})
						.then((res) => {
							if (res.data.code == 200) {
								this.$message({
									message: '修改成功',
									type: 'success'
								})
							} else {
								this.$message.error('修改失败');
							}
							this.getScoreInfo();
						})
						.catch(function(error) {
							console.log(error)
						})
				}
			}
		}
	};
</script>
<style lang="scss" scoped>
	.all {
		padding: 0px 40px;

		.page {
			margin-top: 20px;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.edit {
			margin-left: 20px;
		}

		.el-table tr {
			background-color: #dd5862 !important;
		}
	}

	.el-table .warning-row {
		background: #000 !important;
	}

	.el-table .success-row {
		background: #dd5862;
	}
</style>
